package com.digital.welcome.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.digital.welcome.entity.UserCommunication;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;


// 也可以使用@Component，效果都是一样的，只是为了声明为bean
// 可有可无，可以消去依赖注入的报错信息。
// 表明这个类具有对对象进⾏CRUD（增删改查）的功能
// ⾃动的被@ComponentScan 通过路径扫描给找到
@Mapper
@Repository
public interface UserCommunicationMapper extends BaseMapper<UserCommunication> {
    @Select("SELECT id FROM `user` WHERE user_name in (SELECT user_sophomore FROM user_communication WHERE user_freshman=#{userName})")
    UserCommunication getIdSophomoreByUserName(String userName);

    @Select("SELECT id FROM `user` WHERE user_name in (SELECT user_freshman FROM user_communication WHERE user_sophomore=#{userName})")
    UserCommunication getIdFreshmanByUserName(String userName);

    @Select("SELECT id FROM user_communication WHERE user_sophomore=#{userName} or user_freshman=#{userName}")
    UserCommunication getIdByUserName(String userName);
}
